var service_common = require("common.js");

//对外公开的方法
module.exports = {
  getFindList: getFindList,
  getCollectList: getCollectList,
  getSonList: getSonList,
  getSonSonList: getSonSonList,
  getDemandList: getDemandList,
  getMyDemandList: getMyDemandList,
  getTopicDetail: getTopicDetail,
  wanrenquanDelete: wanrenquanDelete,
  TopicReply: TopicReply,
  TopicLove: TopicLove,
  newReplyCount: newReplyCount,
  topicReplys: topicReplys,
  loveList: loveList
}

/**
 * 获取找合作列表
 */
function getFindList(page, type, cb) {
  service_common.fetchData(
    service_common.getUrl("user.getFindList"),
    {
      page: page,
      type: type,
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}
/**
 * 获取点赞列表
 */
function loveList( topic_id, openid,i,cb){
  service_common.fetchData(
    service_common.getUrl("user.loveList"),
    {
      topic_id: topic_id,
      openid:openid
    },
    (res)=>{
      cb(res,i)
    },
    "GET"
  )
}
/**
 * 获取找合作列表
 */
function topicReplys(page, id, cb) {
  service_common.fetchData(
    service_common.getUrl("user.topicReplys"),
    {
      topic_id: id,
      page: page
    },
    function (res) {
      console.log(res)
      cb(res);
    },
    "GET"
  )
}

/**
 * 用户收到的新回复个数
 */
function newReplyCount(cb) {
  service_common.fetchData(
    service_common.getUrl("user.newReplyCount"),
    {
      openid: getApp().globalData.userInfo.openid,
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}

/**
 * 获取收藏列表
 */  
function getCollectList(page, cb, all = 1) {
  service_common.fetchData(
    service_common.getUrl("user.getCollectList"),
    {
      openid: getApp().globalData.userInfo.openid,
      page: page,
      all: all
    },
    function (res) {
      console.log(res)
      cb(res);
    },
    "GET"
  )
}

/**
 * 获取万人圈列表
 */
function getDemandList(page, cb) {
  console.log('page:'+page)
  service_common.fetchData(
    service_common.getUrl("user.geDemandList"),
    {
      openid: getApp().globalData.userInfo.openid,
      page: page
    },
    function (res) {
      console.log(res)
      cb(res);
    },
    "GET"
  )
}

/**
 * 删除对应我发布的万人圈
 */
function wanrenquanDelete(id, cb) {
  service_common.fetchData(
    service_common.getUrl("user.wanrenquanDelete"),
    {
      openid: getApp().globalData.userInfo.openid,
      topic_id: id
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}

/**
 * 回复万人圈
 */
function TopicReply(id,content, cb) {
  service_common.fetchData(
    service_common.getUrl("user.TopicReply"),
    {
      openid: getApp().globalData.userInfo.openid,
      content: content,
      topic_id: id
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}


/**
 * 点赞万人圈话题
 */
function TopicLove(id, cb) {
  service_common.fetchData(
    service_common.getUrl("user.TopicLove"),
    {
      openid: getApp().globalData.userInfo.openid,
      topic_id: id
    },
    function (res) {
      cb(res);
    },
    "GET",
    true
  )
}

/**
 * 获取我的万人圈列表
 */
function getMyDemandList(page, cb) {
  console.log(page)
  service_common.fetchData(
    service_common.getUrl("user.getMyDemandList"),
    {
      openid: getApp().globalData.userInfo.openid,
      page: page
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}

/**
 * 获取单个话题详情
 */
function getTopicDetail(id, cb) {

  service_common.fetchData(
    service_common.getUrl("user.getTopicDetail"),
    {
      openid: getApp().globalData.userInfo.openid,
      topic_id: id
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}


/**
 * 获取下级用户
 */
function getSonList(page, cb, all = 1) {
  service_common.fetchData(
    service_common.getUrl("user.getSonList"),
    {
      openid: getApp().globalData.userInfo.openid,
      page: page,
      all: all
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}

/**
 * 获取下下级用户
 */
function getSonSonList(page, cb, all = 1) {
  service_common.fetchData(
    service_common.getUrl("user.getSonSonList"),
    {
      openid: getApp().globalData.userInfo.openid,
      page: page,
      all: all
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}